﻿namespace LxBasic
{
    public class LxTool
    {
        public const double OneThird = 1 / 3.0;
        public const double TwoThird = 2 / 3.0;
        public static void FillArray<T>(T[] array, T value, ThreadInfo threadInfo)
        {
            (int i1, int endp1) = new IndexRange(array.Length).Split(threadInfo);
            Array.Fill(array, value, i1, endp1 - i1);
        }
        public static void ClearArray<T>(T[] array, ThreadInfo threadInfo)
        {
            (int i1, int endp1) = new IndexRange(array.Length).Split(threadInfo);
            Array.Clear(array, i1, endp1 - i1);
        }
        public static void CopyArray<T>(T[] source, T[] destination, ThreadInfo threadInfo)
        {
            (int i1, int endp1) = new IndexRange(source.Length).Split(threadInfo);
            Array.Copy(source, i1, destination, i1, endp1 - i1);
        }

        public static void Exchange<T>(ref T a, ref T b)
        {
            T temp = a;
            a = b;
            b = temp;
        }
        public static double RoundOff(double d, int enob)//按有效位数四舍五入
        {
            return double.Parse(d.ToString($"E{enob - 1}"));
        }

    }
}

//public static void CheckCreate<T>(ref T[] Array, int count)
//{
//    if (Array == null || Array.Length != count)
//    {
//        Array = new T[count];
//    }
//}
//public static void CheckCreate<T>(ref T refValue) where T : new()
//{
//    if (refValue == null)
//    {
//        refValue = new T();
//    }
//}
//public static bool CheckCreate<TSpecific, TBase>(ref TBase valueNow, out TSpecific newValue) where TSpecific : class, TBase, new()
//{
//    if (valueNow == null || valueNow.GetType() != typeof(TSpecific))
//    {
//        valueNow = newValue = new TSpecific();
//        return true;
//    }
//    else
//    {
//        newValue = valueNow as TSpecific;
//        return false;
//    }
//}
//public static bool CheckReserve<TSpecific, TBase>(ref TBase valueNow, out TSpecific newValue) where TSpecific : class, TBase, IReserve, new()
//{
//    if (valueNow == null)
//    {
//        valueNow = newValue = new TSpecific();
//        return true;
//    }
//    else if (valueNow.GetType() != typeof(TSpecific))
//    {
//        newValue = new TSpecific();
//        newValue.Reserve(valueNow);
//        valueNow = newValue;
//        return true;
//    }
//    else
//    {
//        newValue = valueNow as TSpecific;
//        return false;
//    }
//}